package com.algorithm;

public class BubbleSort {
    public static void main(String[] args) {
//        int[] ints = {6, 4, 3, 7, 5, 2, 4, 43, 22, 3, -23, 33, 223, 11110};
        int[] ints = {1, 2, 3, 4, 5};
        ints = sort(ints);

        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i] + ",");
        }
        System.out.print("\b");

    }

    static int t = 0;

    public static int[] sort(int[] ints) {
        if (ints == null || ints.length <= 1) {
            return ints;
        }
        int m;
        int j1;
        boolean flag;
        for (int i = ints.length - 1; i >= 0; i--) {
            flag = true;
            for (int j = 0; j < i; j++) {
                System.out.println(++t);

                j1 = j + 1;
                if (ints[j] < ints[j1]) {
                    m = ints[j1];
                    ints[j1] = ints[j];
                    ints[j] = m;
                    flag = false;
                }
            }
            if (flag) {
                return ints;
            }
        }
        return ints;

    }


}
